package Menu;

import graphicswithsomebackup.MouseLocator;
import graphicswithsomebackup.BackGround;
import graphicswithsomebackup.GamePanel;
import java.awt.Graphics;
import java.awt.Image; //image ;P

import javax.swing.ImageIcon;

public class Menu {

    // --------- Primitive types -------------
    private int panelWidth, panelHeight;
    private int upperLeftCornerX = 0;
    private int upperLeftCornerY = 0;
    private boolean fetchingValues = true;//used in getTheWidAndHeightValues to fetch the panelwid- and panelheight-values.
    //.........................................  
    // ----------Reference types -------------
    private BackGround bg;
    private Image titel;
    private MouseLocator mousePositions = new MouseLocator();
    private GamePanel superPanel;
    //.........................................

    //_.-:^:-._.-:^:-._.-:^:-._.-:^:-._.-:^:-._.-:^:-._.-:^:-._.-:^:-._.-:^:-._
    //_.-:^:-._.-:^:-._.-:^:-._.-:^:-._.-:^:-._.-:^:-._.-:^:-._.-:^:-._.-:^:-._

    //----------- BackGround -----------
    private int backgroundX1 = upperLeftCornerX;
    private int backgroundY1 = upperLeftCornerY;
    private int backgroundX2 = upperLeftCornerX;
    private int backgroundY2 = -panelHeight;
    //...................................
    //----------- StartButton -----------
    Button startButton;
    private String start = "start.png";
    private int startCornerX;
    private int startCornerY = 250;
    private int startWidth = 150;
    private int startHeight = 87;
    //...................................
    //----------- HighScoreButton -----------
    Button highScoreButton;
    private String highScore = "hiscore.png";
    private int highScoreCornerX;
    private int highScoreCornerY = 350;
    private int highScoreWidth = 150;
    private int highScoreHeight = 87;
    //...................................
    //----------- Quitbutton -----------
    Button quitButton;
    private String quit = "quit.png";
    private int quitCornerX ;
    private int quitCornerY = 450;
    private int quitWidth = 150;
    private int quitHeight = 87;
    //...................................
    //----------- Roundbutton -----------
    /*Button roundButton;
    private String round = "round.gif";
    private int roundCornerX = 300;
    private int roundCornerY = 200;
    private int roundWidth = 200;
    private int roundHeight = roundWidth;
    //...................................
*/


    public Menu(GamePanel superPanel, int panelWidth, int panelHeight) {

        this.panelWidth = panelWidth;
        this.panelHeight = panelHeight;
        startCornerX = (panelWidth/2) - (startWidth/2) ;
        highScoreCornerX =  (panelWidth/2) - (highScoreWidth/2) ;
        quitCornerX =  (panelWidth/2) - (quitWidth/2) ;

        this.superPanel = superPanel;
        bg = new BackGround(panelWidth, panelHeight);
        titel = new ImageIcon("images/menu/meme.gif").getImage();
        startButton = new Button(start, true, startCornerX, startCornerY, startWidth, startHeight, superPanel, mousePositions );
        highScoreButton = new Button(highScore, true, highScoreCornerX, highScoreCornerY, highScoreWidth, highScoreHeight, superPanel, mousePositions );
        quitButton = new Button(quit, true, quitCornerX, quitCornerY, quitWidth, quitHeight, superPanel, mousePositions);
        //roundButton = new Button(round, false, roundCornerX, roundCornerY, roundWidth, roundHeight, superPanel, mousePositions);
    }
    

    /**
     * Sends forth mousecoordinates to each button-object. By doing so, the objects are able
     * look if the mouse has been pressed inside its borders. Only one mouseLocator-object is ever needed :)
     * And that f**king rocks!
     * @param g
     * @param mouseX
     * @param mouseY
     */
    public void drawMenu( Graphics g, MouseLocator mouseLocator) {
        //draw the buttons and background
        bg.drawBackGround(g); //drawthebackground
        g.drawImage(titel, quitWidth, quitWidth, superPanel);
        startButton.drawButton(g, mouseLocator);
        quitButton.drawButton(g, mouseLocator);
        //roundButton.drawButton(g, mouseLocator);
        highScoreButton.drawButton(g, mouseLocator);
        
        if(startButton.isClicked) {
            superPanel.setMenuIsOn(false); //menu is turned off
            superPanel.setgameIsOn(true); //game is ON baby!
            startButton.isClicked = false;
        }
        if (highScoreButton.isClicked){
            superPanel.setMenuIsOn(false); //menu is turned off
            superPanel.setShowHighScore(true); //showing the highscores!
            highScoreButton.isClicked = false;
        }
        if(quitButton.isClicked) {
            System.exit(0);
        }
    }
}
